/*
 * Created by JFormDesigner on Wed Jun 12 11:26:48 CST 2024
 */

package com.vict.gui;

import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.*;
import java.io.File;
import java.sql.Timestamp;
import java.util.*;
import java.util.List;
import javax.sql.DataSource;
import javax.swing.*;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import com.eltima.components.ui.DatePicker;
import com.vict.ApplicationMain;
import com.vict.GuiApplication;
import com.vict.bean.DbConfig;
import com.vict.bean.TaskExecuteInstance;
import com.vict.config.SettingConfig;
import com.vict.dao.AutoApiSqlMapper;
import com.vict.dao.TaskExecuteInstanceDao;
import com.vict.util.*;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Brainrain
 */
@Slf4j
public class MainWIndowGui extends JFrame {
    static SystemTray tray = SystemTray.getSystemTray();

    private DefaultListModel<String> listModel;
    private DefaultComboBoxModel allDbData;
    private DefaultComboBoxModel allTypeData;
    private DefaultComboBoxModel allServerNameData;
    private DefaultComboBoxModel statusData;
    private DefaultTableModel listData;

    private static DatePicker getDatePicker() {
        final DatePicker datepick;
        // 格式
        String DefaultFormat = "yyyy-MM-dd HH:mm:ss";
        // 当前时间
        Date date = new Date();
        // 字体
        Font font = new Font("Times New Roman", Font.BOLD, 14);

        Dimension dimension = new Dimension(177, 24);

        int[] hilightDays = { 1, 3, 5, 7 };

        int[] disabledDays = { 4, 6, 5, 9 };

        datepick = new DatePicker(date, DefaultFormat, font, dimension);

        datepick.setLocation(137, 83);
        datepick.setBounds(137, 83, 177, 24);
        // 设置一个月份中需要高亮显示的日子
        datepick.setHightlightdays(hilightDays, Color.red);
        // 设置一个月份中不需要的日子，呈灰色显示
        datepick.setDisableddays(disabledDays);
        // 设置国家
        datepick.setLocale(Locale.CHINA);
        // 设置时钟面板可见
        datepick.setTimePanleVisible(true);
        return datepick;
    }

    public MainWIndowGui() {
        initComponents();

        // this.list = new JTable(){
        //     public boolean isCellEditable(int row, int column) {
        //         return false;
        //     }
        // };
        // list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        // list.setFont(list.getFont().deriveFont(list.getFont().getSize() + 4f));
        // scrollPane1.setViewportView(list);

        listModel = new DefaultListModel<String>();
        this.allDbData = new DefaultComboBoxModel<String>();
        this.allTypeData = new DefaultComboBoxModel<String>();
        this.allServerNameData = new DefaultComboBoxModel<String>();
        this.statusData = new DefaultComboBoxModel<String>();
        this.allDb.setModel(this.allDbData);
        this.allTYpeSelect.setModel(this.allTypeData);
        this.serverNameSelect.setModel(allServerNameData);
        this.comboBoxStatus.setModel(this.statusData);
        this.statusData.addElement("全部");
        this.statusData.addElement("待执行");
        this.statusData.addElement("执行中");
        this.statusData.addElement("已完成");
        this.statusData.addElement("已失败");

        this.update();
        // 设置国家
        this.datePicker1.setLocale(Locale.CHINA);
        // 设置时钟面板可见
        this.datePicker1.setTimePanleVisible(true);

        // 设置国家
        this.datePicker2.setLocale(Locale.CHINA);
        // 设置时钟面板可见
        this.datePicker2.setTimePanleVisible(true);

        this.listData = new DefaultTableModel(
                new Object[]{
                        "id",
                        "服务名",
                        "服务id",
                        "任务类型",
                        "状态",
                        "执行次数",
                        "触发时间",
                        "执行json",
                        "上下文",
                        "链接id"
                }, 20);
        this.list.setModel(this.listData);
        this.list.getColumnModel().getColumn(0).setMinWidth(160); // id
        this.list.getColumnModel().getColumn(3).setMinWidth(150); // 任务类型
        // this.list.getColumnModel().getColumn(4).setMaxWidth(80); // 状态
        // this.list.getColumnModel().getColumn(5).setMaxWidth(35); // 执行次数
        this.list.getColumnModel().getColumn(6).setMinWidth(150);
    }

    public void update(){
        this.reloadAllDb();
        this.linkSuccessMsg.setVisible(false);
    }

    private void reloadAllDb(){
        this.allDb.removeAllItems();

        List<DbConfig> dbConfigList = SettingConfig.getDbConfigList();
        for(DbConfig dbConfig : Optional.ofNullable(dbConfigList).orElse(new ArrayList<>())){
            String name = dbConfig.getName();
            this.allDbData.addElement(name);
        }
    }

    /**
     * 选中之后加载全部
     */
    private void allDriveSelect(ActionEvent e) {
        if(listModel == null){
            return;
        }
        listModel.clear();
    }

    private void menuItemLog(ActionEvent e) {
        Optional.ofNullable(GuiApplication.guiApplication)
                .map(o-> o.getLogGui())
                .ifPresent(o-> o.setVisible(true));
    }

    private void dbEdit(ActionEvent e) {
        GuiApplication.guiApplication.getDbEditGui().setVisible(true);
        this.setVisible(false);
    }

    private void updateList(){
        List<String> allType = ApplicationMain.taskExecuteInstanceDao.selectAllType();
        this.allTypeData.removeAllElements();

        this.allTypeData.addElement("全部");
        for(String type : Optional.ofNullable(allType).orElse(new ArrayList<>())){
            this.allTypeData.addElement(type);
        }

        List<String> allServerName = ApplicationMain.taskExecuteInstanceDao.selectAllServerName();
        this.allServerNameData.removeAllElements();
        this.allServerNameData.addElement("全部");
        for(String serverName : Optional.ofNullable(allServerName).orElse(new ArrayList<>())){
            this.allServerNameData.addElement(serverName);
        }
    }

    private void linkBtnAction(ActionEvent e) {
        int selectedIndex = this.allDb.getSelectedIndex();
        DbConfig dbConfig = Optional.ofNullable(SettingConfig.getDbConfigList()).filter(o -> o.size() > 0)
                .map(o -> o.get(selectedIndex)).orElse(null);
        if(dbConfig == null){
            JOptionPane.showMessageDialog(this, "请配置数据源");
        }else{
            try{
                DataSource dataSource = DbUtils.createDataSource(dbConfig.getUrl(), dbConfig.getUsername(), dbConfig.getPassword());
                ApplicationMain.taskExecuteInstanceDao.dataSource = dataSource;
                this.linkSuccessMsg.setText("连接成功");
                this.linkSuccessMsg.setVisible(true);
                this.linkSuccessMsg.setForeground(new Color(51, 255, 0));

                this.updateList();

                ApplicationMain.autoApiSqlMapper.init(dataSource);

            }catch(Exception ex){
                ApplicationMain.taskExecuteInstanceDao.dataSource = null;

                this.linkSuccessMsg.setText("连接失败");
                this.linkSuccessMsg.setVisible(true);
                this.linkSuccessMsg.setForeground(new Color(255, 0, 0));
                log.error("数据库连接失败", ex);
            }

        }
    }

    private void selectListAction(ActionEvent e) {
        this.selectList();
    }

    private void selectList(){
        this.list.removeEditor();
        if(ApplicationMain.taskExecuteInstanceDao.dataSource == null){
            JOptionPane.showMessageDialog(this, "请配置连接数据库");
        }
        String type = Optional.ofNullable(allTYpeSelect).map(o -> o.getSelectedItem()).map(o -> (String) o).map(o -> o.trim())
                .filter(o -> !o.equals("全部")).filter(o-> !o.equals("")).orElse(null);
        String serverName = Optional.ofNullable(serverNameSelect).map(o -> o.getSelectedItem()).map(o -> (String) o).map(o -> o.trim())
                .filter(o -> !o.equals("全部")).filter(o-> !o.equals("")).orElse(null);
        String id = Optional.ofNullable(textFieldID).map(o -> o.getText()).map(o -> o.trim()).filter(o-> !o.equals("")).orElse(null);
        String serverId = Optional.ofNullable(textFieldServerId).map(o -> o.getText()).map(o -> o.trim()).filter(o-> !o.equals("")).orElse(null);

        String status = Optional.ofNullable(comboBoxStatus).map(o -> o.getSelectedItem()).map(o -> (String) o).map(o -> o.trim())
                .filter(o -> !o.equals("全部")).filter(o-> !o.equals("")).orElse(null);
        status = TaskExecuteInstance.convertStatus(status);
        String time1 = Optional.ofNullable(datePicker1).map(o -> o.getText()).map(o -> o.trim()).filter(o-> !o.equals("")).orElse(null);
        String time2 = Optional.ofNullable(datePicker2).map(o -> o.getText()).map(o -> o.trim()).filter(o-> !o.equals("")).orElse(null);

        List<TaskExecuteInstance> taskExecuteInstances = ApplicationMain.taskExecuteInstanceDao.selectList(type, serverName, id, serverId, status, time1, time2,
                Integer.parseInt(this.nowPage.getText()), 20);

        Vector<Vector> dataVector = this.listData.getDataVector();

        this.listData.setRowCount(Optional.ofNullable(taskExecuteInstances).map(o-> o.size()).orElse(0));
        for(int i = 0 ; i < Optional.ofNullable(taskExecuteInstances).map(o-> o.size()).orElse(0) ; i++){
            Vector vector = dataVector.get(i);
            vector.clear();

            int finalI = i;
            TaskExecuteInstance taskExecuteInstance = Optional.ofNullable(taskExecuteInstances).filter(o -> o.size() > finalI).map(o -> o.get(finalI)).orElse(null);
            if(taskExecuteInstance == null){
                // vector.add("");
                continue;
            }
            vector.add(taskExecuteInstance.getTaskExecuteInstanceID());
            vector.add(taskExecuteInstance.getServerName());
            vector.add(taskExecuteInstance.getServerId());
            vector.add(taskExecuteInstance.getType());
            vector.add(TaskExecuteInstance.convertStatus(taskExecuteInstance.getStatus().toString()));
            vector.add(taskExecuteInstance.getExecuteCount());
            vector.add(TimeUtil.getTimeStr(taskExecuteInstance.getActionTime().getTime()));
            vector.add(taskExecuteInstance.getExecuteJSON());
            vector.add(taskExecuteInstance.getStContext());
            vector.add(taskExecuteInstance.getLinkTaskExecuteInstanceID());
        }
        this.list.updateUI();
    }

    private void beforeBtnAction(ActionEvent e) {
        int i = Integer.parseInt(this.nowPage.getText());
        if(i <= 1){
            return;
        }else{
            this.nowPage.setText((i - 1) + "");
            this.list.removeEditor();
            this.selectList();
        }
    }

    private void nextBtnAction(ActionEvent e) {
        int i = Integer.parseInt(this.nowPage.getText());
        this.nowPage.setText((i + 1) + "");
        this.list.removeEditor();
        this.selectList();
    }

    private void retryBtnAction(ActionEvent e) {
        TaskExecuteInstance taskExecuteInstance = selectNowSelectData();
        if(taskExecuteInstance == null){
            JOptionPane.showMessageDialog(this, "请选择要重试的数据");
            return;
        }
        if(taskExecuteInstance.getStatus() == TaskExecuteInstance.status_finish || taskExecuteInstance.getStatus() == TaskExecuteInstance.status_fail){

        }else{
            JOptionPane.showMessageDialog(this, "任务正在进行, 无法重试");
            return;
        }
        int flag = JOptionPane.showConfirmDialog(this, "是否确认重试?",
                "提示!", JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE);
        if(JOptionPane.YES_OPTION == flag){
            ApplicationMain.taskExecuteInstanceDao.updateStatus(taskExecuteInstance.getTaskExecuteInstanceID(), TaskExecuteInstance.status_await);
            this.list.removeEditor();
            this.selectList();
            GuiApplication.message("重试成功");
        }
    }

    private void stopBtnAction(ActionEvent e) {
        TaskExecuteInstance taskExecuteInstance = selectNowSelectData();
        if(taskExecuteInstance == null){
            JOptionPane.showMessageDialog(this, "请选择要终止的数据");
            return;
        }
        if(taskExecuteInstance.getStatus() == TaskExecuteInstance.status_run || taskExecuteInstance.getStatus() == TaskExecuteInstance.status_await){

        }else{
            JOptionPane.showMessageDialog(this, "任务已经结束, 无法终止");
            return;
        }
        int flag = JOptionPane.showConfirmDialog(this, "是否确认终止?",
                "提示!", JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE);
        if(JOptionPane.YES_OPTION == flag){
            ApplicationMain.taskExecuteInstanceDao.updateStatus(taskExecuteInstance.getTaskExecuteInstanceID(), TaskExecuteInstance.status_fail);
            this.list.removeEditor();
            this.selectList();
            GuiApplication.message("终止成功");
        }
    }

    private void editTImeAction(ActionEvent e) {
        TaskExecuteInstance taskExecuteInstance = selectNowSelectData();
        if(taskExecuteInstance == null){
            JOptionPane.showMessageDialog(this, "请选择要修改的数据");
            return;
        }
        if(taskExecuteInstance.getStatus() == TaskExecuteInstance.status_run){
            JOptionPane.showMessageDialog(this, "任务已经开始, 无法修改时间");
            return;
        }
        String time = JOptionPane.showInputDialog(this, "请输入时间?", TimeUtil.getTimeStr(taskExecuteInstance.getActionTime().getTime()));
        if(time == null){
            return;
        }
        if(time == null || time.trim().equals("")){
            JOptionPane.showMessageDialog(this, "请输入正确时间");
            return;
        }

        if(time != null && !time.trim().equals("")){
            ApplicationMain.taskExecuteInstanceDao.updateTime(taskExecuteInstance.getTaskExecuteInstanceID(), time);
            this.list.removeEditor();
            // this.list.clearSelection();
            this.selectList();
            GuiApplication.message("修改时间成功");
        }
    }

    private void serverIDAction(ActionEvent e) {
        TaskExecuteInstance taskExecuteInstance = selectNowSelectData();
        if(taskExecuteInstance == null){
            JOptionPane.showMessageDialog(this, "请选择要修改的数据");
            return;
        }
        if(taskExecuteInstance.getStatus() == TaskExecuteInstance.status_run){
            JOptionPane.showMessageDialog(this, "任务已经开始, 无法修改serverId");
            return;
        }
        String serverId = JOptionPane.showInputDialog(this, "请输入serverId?", taskExecuteInstance.getServerId());
        if(serverId == null){
            // 点击了取消
            return;
        }
        // if(serverId.trim().equals("")){
        //     JOptionPane.showMessageDialog(this, "请输入serverId");
        //     return;
        // }

        ApplicationMain.taskExecuteInstanceDao.updateServerId(taskExecuteInstance.getTaskExecuteInstanceID(), serverId);
        this.list.removeEditor();
        this.selectList();
        GuiApplication.message("修改serverId成功");
        // if(serverId != null && !serverId.trim().equals("")){
        // }
    }

    private void updateActionCount(ActionEvent e) {
        TaskExecuteInstance taskExecuteInstance = selectNowSelectData();
        if(taskExecuteInstance == null){
            JOptionPane.showMessageDialog(this, "请选择要修改的数据");
            return;
        }
        if(taskExecuteInstance.getStatus() == TaskExecuteInstance.status_run){
            JOptionPane.showMessageDialog(this, "任务已经开始, 无法修改执行次数");
            return;
        }
        String executeCount = JOptionPane.showInputDialog(this, "请输入执行次数?",
                Optional.ofNullable(taskExecuteInstance).map(o-> o.getExecuteCount()).map(o-> o.toString()).orElse(null)
        );
        if(executeCount == null){
            return;
        }
        if(executeCount == null || executeCount.trim().equals("")){
            JOptionPane.showMessageDialog(this, "请输入执行次数");
            return;
        }

        if(executeCount != null && !executeCount.trim().equals("")){
            ApplicationMain.taskExecuteInstanceDao.updateExecuteCount(taskExecuteInstance.getTaskExecuteInstanceID(), executeCount);
            this.list.removeEditor();
            this.selectList();
            GuiApplication.message("修改执行次数成功");
        }
    }

    public JLabel getMessage(){
        return this.message;
    }

    private TaskExecuteInstance selectNowSelectData(){
        int selectedRow = this.list.getSelectedRow();
        if(selectedRow == -1){
            return null;
        }
        Vector vector = this.listData.getDataVector().get(selectedRow);

        TaskExecuteInstance taskExecuteInstance = new TaskExecuteInstance();

        String taskExecuteInstanceID = Optional.ofNullable(vector).map(o -> o.get(0)).map(o -> o.toString()).map(o -> (String) o).orElse(null);
        String serverName = Optional.ofNullable(vector).map(o -> o.get(1)).map(o -> o.toString()).map(o -> (String) o).orElse(null);
        String serverId = Optional.ofNullable(vector).map(o -> o.get(2)).map(o -> o.toString()).map(o -> (String) o).orElse(null);
        String type = Optional.ofNullable(vector).map(o -> o.get(3)).map(o -> o.toString()).map(o -> (String) o).orElse(null);
        Integer status = Optional.ofNullable(vector).map(o -> o.get(4)).map(o -> o.toString()).map(o -> (String) o).map(o-> TaskExecuteInstance.convertStatus(o)).map(o-> Integer.valueOf(o)).orElse(null);
        Integer executeCount = Optional.ofNullable(vector).map(o -> o.get(5)).map(o -> o.toString()).map(o -> (String) o).map(o-> Integer.valueOf(o)).orElse(null);
        Timestamp actionTime = Optional.ofNullable(vector).map(o -> o.get(6)).map(o -> o.toString()).map(o -> (String) o).map(o-> TimeUtil.getTime(o)).map(o-> new Timestamp(o)).orElse(null);
        String executeJSON = Optional.ofNullable(vector).map(o -> o.get(7)).map(o -> o.toString()).map(o -> (String) o).orElse(null);
        String stContext = Optional.ofNullable(vector).map(o -> o.get(8)).map(o -> o.toString()).map(o -> (String) o).orElse(null);
        String linkTaskExecuteInstanceID = Optional.ofNullable(vector).map(o -> o.get(9)).map(o -> o.toString()).map(o -> (String) o).orElse(null);

        taskExecuteInstance.setTaskExecuteInstanceID(taskExecuteInstanceID);
        taskExecuteInstance.setServerName(serverName);
        taskExecuteInstance.setServerId(serverId);
        taskExecuteInstance.setType(type);
        taskExecuteInstance.setStatus(status);
        taskExecuteInstance.setExecuteCount(executeCount);
        taskExecuteInstance.setActionTime(actionTime);
        taskExecuteInstance.setExecuteJSON(executeJSON);
        taskExecuteInstance.setStContext(stContext);
        taskExecuteInstance.setLinkTaskExecuteInstanceID(linkTaskExecuteInstanceID);

        return taskExecuteInstance;
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        menuBar1 = new JMenuBar();
        menu2 = new JMenu();
        menuItem3 = new JMenuItem();
        menuItem1 = new JMenuItem();
        allDb = new JComboBox();
        label1 = new JLabel();
        scrollPane1 = new JScrollPane();
        list = new JTable();
        linkBtn = new JButton();
        linkSuccessMsg = new JLabel();
        label2 = new JLabel();
        allTYpeSelect = new JComboBox();
        label3 = new JLabel();
        serverNameSelect = new JComboBox();
        label4 = new JLabel();
        textFieldID = new JTextField();
        label5 = new JLabel();
        textFieldServerId = new JTextField();
        label6 = new JLabel();
        comboBoxStatus = new JComboBox();
        datePicker1 = new DatePicker();
        datePicker2 = new DatePicker();
        label7 = new JLabel();
        buttonSelectList = new JButton();
        nextBtn = new JButton();
        beforeBtn = new JButton();
        nowPage = new JLabel();
        retryBtn = new JButton();
        stopBtn = new JButton();
        message = new JLabel();
        editTIme = new JButton();
        buttonServerID = new JButton();
        button1 = new JButton();
        label8 = new JLabel();

        //======== this ========
        setIconImage(new ImageIcon(getClass().getResource("/icon.png")).getImage());
        setFont(new Font(Font.DIALOG, Font.PLAIN, 14));
        setResizable(false);
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== menuBar1 ========
        {

            //======== menu2 ========
            {
                menu2.setText("\u7cfb\u7edf");

                //---- menuItem3 ----
                menuItem3.setText("\u65e5\u5fd7");
                menuItem3.addActionListener(e -> menuItemLog(e));
                menu2.add(menuItem3);

                //---- menuItem1 ----
                menuItem1.setText("\u7f16\u8f91\u6570\u636e\u5e93");
                menuItem1.addActionListener(e -> dbEdit(e));
                menu2.add(menuItem1);
            }
            menuBar1.add(menu2);
        }
        setJMenuBar(menuBar1);

        //---- allDb ----
        allDb.addActionListener(e -> allDriveSelect(e));
        contentPane.add(allDb);
        allDb.setBounds(90, 20, 185, allDb.getPreferredSize().height);

        //---- label1 ----
        label1.setText("\u9009\u62e9\u6570\u636e\u5e93:");
        contentPane.add(label1);
        label1.setBounds(20, 25, 80, label1.getPreferredSize().height);

        //======== scrollPane1 ========
        {

            //---- list ----
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            list.setFont(list.getFont().deriveFont(list.getFont().getSize() + 4f));
            scrollPane1.setViewportView(list);
        }
        contentPane.add(scrollPane1);
        scrollPane1.setBounds(20, 235, 1130, 345);

        //---- linkBtn ----
        linkBtn.setText("\u8fde\u63a5");
        linkBtn.addActionListener(e -> linkBtnAction(e));
        contentPane.add(linkBtn);
        linkBtn.setBounds(new Rectangle(new Point(300, 20), linkBtn.getPreferredSize()));

        //---- linkSuccessMsg ----
        linkSuccessMsg.setText("\u8fde\u63a5\u6210\u529f");
        linkSuccessMsg.setForeground(Color.red);
        linkSuccessMsg.setVisible(false);
        contentPane.add(linkSuccessMsg);
        linkSuccessMsg.setBounds(395, 25, 75, linkSuccessMsg.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u7c7b\u578b:");
        contentPane.add(label2);
        label2.setBounds(20, 90, 50, label2.getPreferredSize().height);
        contentPane.add(allTYpeSelect);
        allTYpeSelect.setBounds(65, 85, 235, allTYpeSelect.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u670d\u52a1\u540d:");
        contentPane.add(label3);
        label3.setBounds(325, 90, 100, label3.getPreferredSize().height);
        contentPane.add(serverNameSelect);
        serverNameSelect.setBounds(455, 85, 210, serverNameSelect.getPreferredSize().height);

        //---- label4 ----
        label4.setText("ID:");
        contentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(20, 140), label4.getPreferredSize()));
        contentPane.add(textFieldID);
        textFieldID.setBounds(65, 135, 235, 30);

        //---- label5 ----
        label5.setText("\u672c\u5730\u670d\u52a1ID(serverId):");
        contentPane.add(label5);
        label5.setBounds(325, 140, 165, label5.getPreferredSize().height);
        contentPane.add(textFieldServerId);
        textFieldServerId.setBounds(455, 135, 210, 30);

        //---- label6 ----
        label6.setText("\u72b6\u6001:");
        contentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(20, 190), label6.getPreferredSize()));
        contentPane.add(comboBoxStatus);
        comboBoxStatus.setBounds(65, 185, 235, comboBoxStatus.getPreferredSize().height);
        contentPane.add(datePicker1);
        datePicker1.setBounds(400, 190, 160, datePicker1.getPreferredSize().height);
        contentPane.add(datePicker2);
        datePicker2.setBounds(new Rectangle(new Point(580, 190), datePicker2.getPreferredSize()));

        //---- label7 ----
        label7.setText("\u89e6\u53d1\u65f6\u95f4:");
        contentPane.add(label7);
        label7.setBounds(325, 190, 90, label7.getPreferredSize().height);

        //---- buttonSelectList ----
        buttonSelectList.setText("\u67e5\u8be2");
        buttonSelectList.addActionListener(e -> selectListAction(e));
        contentPane.add(buttonSelectList);
        buttonSelectList.setBounds(new Rectangle(new Point(795, 85), buttonSelectList.getPreferredSize()));

        //---- nextBtn ----
        nextBtn.setText("\u4e0b\u4e00\u9875");
        nextBtn.addActionListener(e -> nextBtnAction(e));
        contentPane.add(nextBtn);
        nextBtn.setBounds(new Rectangle(new Point(1055, 595), nextBtn.getPreferredSize()));

        //---- beforeBtn ----
        beforeBtn.setText("\u4e0a\u4e00\u9875");
        beforeBtn.addActionListener(e -> beforeBtnAction(e));
        contentPane.add(beforeBtn);
        beforeBtn.setBounds(new Rectangle(new Point(900, 595), beforeBtn.getPreferredSize()));

        //---- nowPage ----
        nowPage.setText("1");
        contentPane.add(nowPage);
        nowPage.setBounds(1010, 600, 20, nowPage.getPreferredSize().height);

        //---- retryBtn ----
        retryBtn.setText("\u91cd\u8bd5");
        retryBtn.addActionListener(e -> retryBtnAction(e));
        contentPane.add(retryBtn);
        retryBtn.setBounds(new Rectangle(new Point(25, 595), retryBtn.getPreferredSize()));

        //---- stopBtn ----
        stopBtn.setText("\u7ec8\u6b62");
        stopBtn.addActionListener(e -> stopBtnAction(e));
        contentPane.add(stopBtn);
        stopBtn.setBounds(new Rectangle(new Point(115, 595), stopBtn.getPreferredSize()));

        //---- message ----
        message.setText("\u72b6\u6001\u680f");
        contentPane.add(message);
        message.setBounds(10, 640, 595, message.getPreferredSize().height);

        //---- editTIme ----
        editTIme.setText("\u4fee\u6539\u65f6\u95f4");
        editTIme.addActionListener(e -> editTImeAction(e));
        contentPane.add(editTIme);
        editTIme.setBounds(new Rectangle(new Point(205, 595), editTIme.getPreferredSize()));

        //---- buttonServerID ----
        buttonServerID.setText("\u4fee\u6539serverId");
        buttonServerID.addActionListener(e -> serverIDAction(e));
        contentPane.add(buttonServerID);
        buttonServerID.setBounds(new Rectangle(new Point(320, 595), buttonServerID.getPreferredSize()));

        //---- button1 ----
        button1.setText("\u4fee\u6539\u6267\u884c\u6b21\u6570");
        button1.addActionListener(e -> updateActionCount(e));
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(455, 595), button1.getPreferredSize()));

        //---- label8 ----
        label8.setText("~");
        contentPane.add(label8);
        label8.setBounds(565, 190, 20, label8.getPreferredSize().height);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(1175, 725);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JMenuBar menuBar1;
    private JMenu menu2;
    private JMenuItem menuItem3;
    private JMenuItem menuItem1;
    private JComboBox allDb;
    private JLabel label1;
    private JScrollPane scrollPane1;
    private JTable list;
    private JButton linkBtn;
    private JLabel linkSuccessMsg;
    private JLabel label2;
    private JComboBox allTYpeSelect;
    private JLabel label3;
    private JComboBox serverNameSelect;
    private JLabel label4;
    private JTextField textFieldID;
    private JLabel label5;
    private JTextField textFieldServerId;
    private JLabel label6;
    private JComboBox comboBoxStatus;
    private DatePicker datePicker1;
    private DatePicker datePicker2;
    private JLabel label7;
    private JButton buttonSelectList;
    private JButton nextBtn;
    private JButton beforeBtn;
    private JLabel nowPage;
    private JButton retryBtn;
    private JButton stopBtn;
    private JLabel message;
    private JButton editTIme;
    private JButton buttonServerID;
    private JButton button1;
    private JLabel label8;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
